package com.foo.demo.dao;

import com.foo.demo.dao.model.User;

import java.util.List;

public class UserDao extends BaseDao{

    public List<User> queryAllUser() {
        String sql = "select * from t_user";
        Object[] arr = new Object[0];
        List<User> users = queryForList(sql, arr, User.class);
        return users;
    }

    public User queryUserByUsername(String username) {
        String sql = "select * from t_user where username = ?";

        User user = queryForObject(sql, new Object[]{username}, User.class);

        return user;
    }

    public int addUser(User user) {
        String sql = "insert into t_user(nick_name, username, password) values (?, ?, ?)";
        return insert(sql, new Object[]{user.getNickName(), user.getUsername(), user.getPassword()});
    }
}
